<%@ Page Language="C#" MasterPageFile="~/Forum.master" AutoEventWireup="true" CodeBehind="RegistrationPage.aspx.cs" Inherits="Forums.RegistrationPage" %>

<asp:Content ID="register" runat="server" ContentPlaceHolderID="mainContentHolder">
    <asp:SqlDataSource ID="newUser" runat="server" ConnectionString="<%$ConnectionStrings:CentForumsDB%>" 
         InsertCommand="INSERT INTO dbo.Registration (member_name, first_name, last_name, email, password, date_joined) 
                        VALUES (@user, @fName, @lName, @email, pwdencrypt(@password), getdate())">    
        <InsertParameters>
            <asp:Parameter Name="user" />
            <asp:Parameter Name="fName" />
            <asp:Parameter Name="lName" />
            <asp:Parameter Name="email" />
            <asp:Parameter Name="password"  />                     
        </InsertParameters>
    </asp:SqlDataSource>

    <asp:FormView ID="registrationForm" runat="server" AllowPaging="false" DataKeyNames="user_accnt"
         DataSourceID="newUser" DefaultMode="Insert" 
        oniteminserted="registrationForm_ItemInserted">        
    <InsertItemTemplate>
    <table id="registration" >
        <tr>
            <td class="text">
                User Name
            </td>
            <td>
                <asp:TextBox ID="txtUser" runat="server" MaxLength="100"  Text='<%#Bind("user")%>' AutoPostBack="true" OnTextChanged="userCheck" ></asp:TextBox>
                <asp:Label ID="lblUser" runat="server" Visible="false" SkinID="error" Text="User name taken!"></asp:Label>                                
            </td>
        </tr>
        <tr>
            <td class="text">
                Password
            </td>
            <td>
                <asp:TextBox ID="txtPassword" runat="server" MaxLength="9" TextMode="Password"
                     Text='<%#Bind("password")%>'></asp:TextBox>
            </td>
            <td class="text">
                Confirm Password
            </td>
            <td>
                <asp:TextBox ID="txtPassCheck" runat="server" MaxLength="9" TextMode="Password"></asp:TextBox>
                <asp:CompareValidator ID="passwordCheck" runat="server" ControlToValidate="txtPassCheck" ControlToCompare="txtPassword"
                     ErrorMessage="Does not match" CssClass="errorMessage" />
            </td>
        </tr>
        <tr>
            <td class="text">
                First Name
            </td>
            <td>
                <asp:TextBox ID="txtFName" runat="server" MaxLength="100" Text='<%#Bind("fName")%>'></asp:TextBox>
            </td>
            <td class="text"> 
                Last Name
            </td>
            <td>
                <asp:TextBox ID="txtLName" runat="server" MaxLength="100" Text='<%#Bind("lName")%>'></asp:TextBox></td></tr><tr>
            <td class="text">
                Email
            </td>
            <td>
                <asp:TextBox ID="txtEmail" runat="server" MaxLength="32" Text='<%#Bind("email")%>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="emailCheck" Text="Invalid email" runat="server" CssClass="errorMessage"
                 ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
            </td>
        </tr>
        <tr>
            <td> 
                <br />
            </td>
        </tr>
        <tr>
            <td> 
                <asp:Button ID="btnSubmit" runat="server" CssClass="submitButton" Text="Register" CommandName="Insert"/>
                <asp:CustomValidator ID="fieldsRequired" CssClass="errorMessage" OnServerValidate="requiredFields" 
                     runat="server" ErrorMessage=" All fields are required!" />                                         
            </td>
            <td>
                <asp:Button ID="btnCancel" CssClass="submitButton" CausesValidation="false" runat="server" 
                     Text="Cancel" OnClick="btnCancel" />
            </td>
        </tr>        
    </table>
    </InsertItemTemplate>
    </asp:FormView>        
</asp:Content>